import getProp from './prop'

/**
 * 获取验证字段
 * @param {*} { fields }
 * @return {*} rule
 */
function _getRules ({ fields }) {
  const { label } = getProp({ fields })
  const { verification } = fields
  const { required } = verification

  return [{ required, message: `请输入${label}` }]
}

/**
 * @export 获取bable类型表单属性
 * @param {*} { fields }
 * @return {*} prop
 */
export default function getTableProp ({ fields }) {
  const { setting, verification } = fields
  const { max_row = 0, min_row = 0 } = verification
  const { add: addButton, delete: deleteButton } = setting

  const rules = _getRules({ fields })

  return {
    ...getProp({ fields }),
    maxRow: max_row || 0,
    minRow: min_row || 0,
    columns: fields.table.fields,
    addButton,
    deleteButton,
    rules,
  }
}
